package com.renli.service.impl;

import com.renli.bean.ResultJson;
import com.renli.mapper.DepartmentMapper;
import com.renli.pojo.Department;
import com.renli.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DepartmentServiceImpl implements DepartmentService {
    @Autowired
    private DepartmentMapper departmentMapper;

    @Override
    public ResultJson add(Department dep) {

        if (departmentMapper.add(dep) == 1) {
            return new ResultJson().setSuccess("添加成功");
        } else {
            return new ResultJson().setSuccess("添加失败");
        }
    }

    @Override
    public ResultJson delDep(Integer depId) {

        if (departmentMapper.del(depId)==1){
            return new ResultJson().setSuccess("删除成功");
        }else {
            return new ResultJson().setSuccess("删除失败");
        }
    }

    @Override
    public ResultJson<List<Department>> findAll() {
        List<Department> departments = departmentMapper.selectAllDepartment();
        ResultJson<List<Department>> resultJson = new ResultJson<>();
        resultJson.setSuccess("查询成功", departments);
        return resultJson;
    }
}
